package logic

import (
	"context"
	"novel-start/api/internal/svc"
	"novel-start/api/internal/types"
	"novel-start/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RePasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RePasswordLogic {
	return &RePasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RePasswordLogic) RePassword(req *types.RePasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	date, err := l.svcCtx.NovelRpc.RePassword(l.ctx, &novelrpc.RePasswordRequest{
		UserId:      req.UserId,
		Mobile:      req.Mobile,
		SendSms:     req.SendSms,
		Password:    req.Password,
		AckPassword: req.AckPassword,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Date:    nil,
		}, nil
	}

	return &types.Response{
		Message: "密码重置成功",
		Code:    200,
		Date:    date,
	}, nil
}
